//
//  PostCell.m
//  mid-view
//
//  Created by sus183 on 2020/12/4.
//  Copyright © 2020 itlab. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "PostCell.h"

@implementation PostCell
-(id)init{
    self = [super init];
    if(self){
        [self.contentView setBackgroundColor:[UIColor clearColor]];
        self.layer.borderColor = [UIColor grayColor].CGColor;
        self.layer.borderWidth = 2.0;
        self.layer.cornerRadius = 10.0;  // 圆角
        
        UIImageView* profilePic  = [[UIImageView alloc]initWithFrame:CGRectMake(10,10,60,60)];
        UIImage *image = [UIImage imageNamed:@"profilePic.jpg"];
        [profilePic setImage:image];
        profilePic.layer.masksToBounds =YES;
        profilePic.layer.cornerRadius = 30;
        [self.contentView addSubview:profilePic];
        
        [self setUserNameLabel:[[UILabel alloc]initWithFrame:CGRectMake(80,10,200,20)] ];
        self.userNameLabel.text = @"UserName";
        [self.contentView addSubview:self.userNameLabel];
        
        [self setTimeLabel: [[UILabel alloc]initWithFrame:CGRectMake(80,40,200,20)]];
        self.timeLabel.text = @"21:36 2020/12/4";
        [self.contentView addSubview:self.timeLabel];
        
        [self setContentLabel: [[UILabel alloc]initWithFrame:CGRectMake(10,80,300,100)]];
        //self.contentLabel.layer.borderWidth = 1.0;
        //self.contentLabel.layer.borderColor = [[UIColor grayColor] CGColor];
        self.contentLabel.text = @"content";
        [self.contentView addSubview:self.contentLabel];
         
        
        
    }
    return self;
}

-(void)updateCellWithMode:Model{
    //self.textLabel.text = [Model getName];
    //self.textLabel.numberOfLines = 0;
    //self.textLabel.text = [[NSString alloc] initWithFormat:@"Name：        %@\nDate：        %@\nTag：          %@\nContext：%@\n Likes：          %d\n", [Model getName], [Model getTime], [Model getTags], [Model getContent],[Model getLikesNum]];
    self.timeLabel.text = [Model getTime];
    self.userNameLabel.text = [Model getName];
    self.contentLabel.text = [Model getContent];
    self.contentLabel.numberOfLines = 0;
    [self.contentLabel sizeToFit];
    UIButton  *likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    likeButton.frame = CGRectMake(321 , 130, 20, 20);
    likeButton.tag =[Model getLikesNum];
    [likeButton setImage:[UIImage imageNamed:@"like.png"] forState:UIControlStateNormal];
    [likeButton addTarget:self action:@selector(likeButtonClicked:) forControlEvents:UIControlEventTouchDown];
    //likeButton.tag = indexPath.row;
    [self.contentView addSubview:likeButton];
    
    UIButton  *commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
    commentButton.frame = CGRectMake(171 , 130, 20, 20);
    commentButton.tag =[Model getLikesNum];
    [commentButton setImage:[UIImage imageNamed:@"comment.png"] forState:UIControlStateNormal];
    [commentButton addTarget:self action:@selector(commentButtonClicked:) forControlEvents:UIControlEventTouchDown];
    //commentButton.tag = indexPath.row;
    [self.contentView addSubview:commentButton];
    
    UIButton  *starButton = [UIButton buttonWithType:UIButtonTypeCustom];
    starButton.frame = CGRectMake(21 , 130, 20, 20);
    starButton.tag =[Model getLikesNum];
    [starButton setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
    [starButton addTarget:self action:@selector(starButtonClicked:) forControlEvents:UIControlEventTouchDown];
    //starButton.tag = indexPath.row;
    [self.contentView addSubview:starButton];
   // [self.contentView addSubview:[[UIView alloc]initWithFrame:CGRectMake(10.0f,150.0f,300.0f,10.0f)]];
    //return cell;
}

- (void)likeButtonClicked:(nonnull SingleCard *)Model{
    int n =[Model getLikesNum];
    n = n+1;
    NSLog(@"Like = %d ++",n);
    [Model setLikesNum:n];
    return;
}
-(void)setFrame:(CGRect)frame{
    frame.origin.x += 10;
    frame.origin.y += 10;
    frame.size.height -= 10;
    frame.size.width -= 20;
    [super setFrame:frame];
}

@end
